home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
usenet
/
sources
/
volume91
/
news
/
vnres112
/
part02
/
envir_set.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-14
|
4KB
|
201 lines
/*
** vn news reader.
**
** envir_set.c - routine to obtain pertinent environment variable settings
** and set up file / directory names
**
** see copyright disclaimer / history in vn.c source file
*/
#include <stdio.h>
#include <pwd.h>
#ifndef MINIX
#ifndef MSDOS
#ifndef amiga
/* minix does not have this */
#include <sys/param.h>
#endif
#endif
#endif
#include "tune.h"
#include "config.h"
#include "vn.h"
extern char *Editor, *Ps1, *Printer;
extern char *Orgdir, *Savedir, *Ccfile; /* path names */
extern char Cxitop[], Cxitor[], Cxrtoi[], Cxptoi[];
extern char *Home;
extern int More;
#ifdef SYSV
#ifndef amiga
extern char *getcwd();
#endif
#define getwd(a) getcwd(a,sizeof(a))
#define MAXPATHLEN 240
#else
extern char *getwd();
#endif
static set_kxln ();
static char xln_str ();
/*
environment variable, original directory string setup.
*/
envir_set ()
{
char dbuf [MAXPATHLEN], *ccname, *keyxln;
char *vn_env(), *str_store();
#ifndef amiga
char * *getcwd();
#endif
struct passwd *ptr, *getpwuid();
vns_envir();
More = 0;
Ps1 = vn_env("PS1",DEF_PS1);
Editor = vn_env("EDITOR",DEF_ED);
Printer = vn_env("PRINTER",DEF_PRINT);
ccname = vn_env("CCFILE",DEF_CCFILE);
keyxln = vn_env("VNKEY",DEF_KEYXLN);
Savedir = vn_env("VNSAVE",NULL);
More = (strcmp(vn_env("MORE",""), "-c") == 0 ? TRUE : FALSE);
/*
set original directory strings.
*/
if ((ptr = getpwuid(getuid())) == NULL)
printex("Cannot obtain /etc/passwd entry");
Home = str_store(ptr->pw_dir);
if ((Orgdir = getwd(dbuf)) == NULL)
printex ("cannot stat pwd");
Orgdir = str_store (Orgdir);
if (Savedir == NULL)
Savedir = Orgdir;
if (*ccname != DIRSEP)
{
#ifdef amiga
sprintf (dbuf, "%s%s",Home,ccname);
#else
sprintf (dbuf, "%s%c%s",Home,DIRSEP,ccname);
#endif
Ccfile = str_store (dbuf);
}
else
Ccfile = str_store (ccname);
#ifdef amiga
sprintf (dbuf, "%s%s%s",Home,"vn","XXXXXX");
#else
sprintf (dbuf, "%s%c%s%s",Home,DIRSEP,"vn","XXXXXX");
#endif
if (*keyxln != DIRSEP)
{
#ifdef amiga
sprintf(dbuf, "%s%s",Home,keyxln);
#else
sprintf(dbuf, "%s%c%s",Home,DIRSEP,keyxln);
#endif
set_kxln(dbuf);
}
else
set_kxln(keyxln);
}
char *
vn_env(var,def)
char *var;
char *def;
{
char pfx[RECLEN];
char *res;
char *getenv();
char * GetConfig(char *field, char *def);
if (var[0] != 'V' || var[1] != 'N')
{
sprintf(pfx,"VN%s",var);
#ifdef amiga
if ((res = GetConfig(pfx, NULL)) == NULL)
if ((res = getenv(pfx)) != NULL)
return(res);
return(res);
#else
if ((res = getenv(pfx)) != NULL)
return(res);
#endif
}
#ifdef amiga
if ((res = GetConfig(var, NULL)) == NULL)
if ((res = getenv(var)) != NULL)
return(res);
return(res);
#else
if ((res = getenv(var)) != NULL)
return(res);
#endif
return(def);
}
static
set_kxln(fname)
char *fname;
{
FILE *fp;
int i;
char bufr[80];
char in,out,*ptr;
char *index();
for (i=0; i < CHMASK+1; ++i)
Cxitop[i] = Cxitor[i] = Cxptoi[i] = Cxrtoi[i] = i;
if ((fp = fopen(fname,"r")) != NULL)
{
while(fgets(bufr,79,fp) != NULL)
{
if (strncmp(bufr+1,"==",2) == 0)
ptr = bufr+2;
else
ptr = index(bufr+1,'=');
if (ptr == NULL)
continue;
*ptr = '\0';
++ptr;
in = xln_str(bufr+1);
out = xln_str(ptr);
switch(bufr[0])
{
case 'r':
case 'R':
Cxrtoi[out] = in;
Cxitor[in] = out;
break;
case 'p':
case 'P':
Cxptoi[out] = in;
Cxitop[in] = out;
default:
break;
}
}
fclose(fp);
}
}
static char
xln_str(s)
char *s;
{
if (*s < '0' || *s > '9')
return(*s & CHMASK);
return((char)(atoi(s) & CHMASK));
}